package com.example.first;

import static androidx.constraintlayout.motion.utils.Oscillator.TAG;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    TextView out;
    EditText edit1,edit2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        out= (TextView)findViewById(R.id.txtout);
        edit1=(EditText)findViewById(R.id.inp1);
        edit2=(EditText)findViewById(R.id.inp2);
        Button btn=(Button)findViewById(R.id.btn);
        btn.setOnClickListener(this);
        Log.i("aaa", "onCreate: ");

    }

    @Override
    public void onClick(View view) {
        Log.i("main", "onClick msg.... ");
        double h=Double.parseDouble(edit1.getText().toString());
        double w=Double.parseDouble(edit2.getText().toString());
        double result;
        result=w/(h*h);
        String str1="BMI";
        String str2=String.format("%.2f",result);
        if(result<18.5){
            str1="过轻，建议加大进食量，多运动";
        }
        else if(result<24)
            str1="正常，请继续保持";
        else if(result<28)
            str1="超重，建议合理膳食，加强运动";
        else if (result<35)
            str1="肥胖，请合理膳食，加强运动";
        else if (result>=35)
            str1="过度肥胖，建议去医院就医并且及时遵医嘱减肥";
        out.setText("你的BMI指数为"+str2+","+str1);
    }
}